number = int(input("Введите число: "))

if number<1000 or number>9999:
 print("Результат: 0")

else:

 simple = int(0)

 for x in range(0, 4):
  variant = str(number)[x:]
  if int(variant) % 2 != 0:
   d = 3
   while d * d <= int(variant) and int(variant) % d != 0:
    d += 2
   if (bool(d * d > int(variant) and int(variant) != 1)):  
    if int(variant) > simple:
     simple = int(variant)

  for y in range(1, 4-x):
   variant2 = str(variant)[:-y]
   if int(variant2) % 2 != 0:
    d = 3
    while d * d <= int(variant2) and int(variant2) % d != 0:
     d += 2
    if (bool(d * d > int(variant2) and int(variant2) != 1)):
     if int(variant2) > simple:
      simple = int(variant2)
     
 print("Результат:", simple)